package com.steam.xbcc.utils;

import com.alibaba.fastjson.JSON;
import com.steam.xbcc.dto.LoginContextDto;
import com.steam.xbcc.enums.GlobalExceptionCode;
import com.steam.xbcc.util.AssertUtil;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;

public class LoginContextUtil {

    public static LoginContextDto getLoginContext(){
        // 3.1.在此处需要得到当前登录用户设置上架人
        SecurityContext context = SecurityContextHolder.getContext();
        Authentication authentication = context.getAuthentication();
        AssertUtil.isTrue(authentication.isAuthenticated(), GlobalExceptionCode.ERROR);
        return JSON.parseObject(authentication.getPrincipal().toString(), LoginContextDto.class);
    }

}